<template>
  <header class="ly-sidebar">
    <el-row class="tac">
      <el-col>
        <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            background-color="#304156"
            text-color="#fff"
            active-text-color="#608bf5">
          <div v-for="(item,index) in menu" :key="index">
            <el-submenu v-if="item.list" :index="item.type">
              <template slot="title">
                <i class="iconfont" :class="item.icon"></i>
                <span>{{item.title}}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item v-for="(type,index1) in item.list" :index="item.type+'-'+type.type" :key="index1"
                              @click="$router.push({path:'/'+item.type,query:{id:type.id,name:type.title}})">
                  {{type.title}}
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>
            <el-menu-item v-else :index="item.type" @click="$router.push('/'+item.type)">
              <i class="iconfont" :class="item.icon"></i>
              <span slot="title">{{item.title}}</span>
            </el-menu-item>
          </div>
        </el-menu>
      </el-col>
    </el-row>
  </header>
</template>

<script>
  import {mapState} from 'vuex'

  export default {
    name: 'sidebar',
    data() {
      return {}
    },
    computed: {
      ...mapState([
        'menu'
      ]),
    },
    watch: {
      $route() {
        let data = this.$route.meta.title
        if (this.$route.query) {
          if (this.$route.query.name) {
            data = this.$route.query.name
          }
        }
        this.$store.commit('updateMetaTitleData', data)
      }
    },
    methods: {},
  }
</script>

<style scoped lang="scss">
  .ly-sidebar {
    background: #304156;
    height: calc(100% - 60px);
    position: fixed;
    top: 60px;
    left: 0;
    width: 205px;
    z-index: 90;
    border-right: 5px solid #e4e4e4;

    i {
      &.iconfont {
        font-size: 18px;
        margin-right: 5px;
      }
    }
  }
</style>
